package com.etc.order.provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.etc.order.common.domain.ProductInfo;
import com.etc.order.common.service.ProductInfoService;
import com.etc.order.provider.mapper.ProductInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ProductInfoServiceImpl implements ProductInfoService {
    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<ProductInfo> findAll(int pageIndex, int pageSize) {
        return productInfoMapper.getAll(pageIndex, pageSize);
    }

    @Override
    public List<ProductInfo> findByProductName(String productName, int pageIndex, int pageSize) {
        return productInfoMapper.findByProductName(productName, pageIndex, pageSize);
    }

    @Override
    public List<ProductInfo> getFoods(Integer categoryType) {
        return productInfoMapper.getFoods(categoryType);
    }

    @Override
    public ProductInfo getOne(String productId) {
        return productInfoMapper.getOne(productId);
    }

    @Override
    public int getTotalCount(String productName) {
        return productInfoMapper.getTotalCount(productName);
    }

    @Override
    public int save(ProductInfo info) {
        if (getOne(info.getProductId()) != null) {
            return productInfoMapper.update(info);
        } else {
            return productInfoMapper.save(info);
        }
    }

    @Override
    public int delete(String productId) {
        return productInfoMapper.delete(productId);
    }

    @Override
    public int decreaseStock(String productId, int productStock) {
        return productInfoMapper.decreaseStock(productId, productStock);
    }
}
